import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsxPlugin from "@vitejs/plugin-vue-jsx";
import { emjoSelf } from "./my-plugin/vite-plugin-emjo-self";

// import compress from "vite-plugin-compress";

// console.log("process.env:", process.env.NODE_ENV);
// console.log("process.env.VITE_APP_TITLE:", process.env.VITE_APP_TITLE);

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsxPlugin(), emjoSelf()],
  // root: './',
  // base: './',
  // publicDir: 'public',
  server: {
    //服务器选项
    port: 3000,
    open: true,
    cors: true,
    proxy: {
      "/api": {
        target: "http://localhost:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  build: {
    //构建选项
    // target: 'es2015',//默认modules
    // outDir: 'dist',
    // assetsDir: 'assets',
    // assetsInlineLimit: 4096,
    // cssCodeSplit: true,
    // cssMinify: 'simple',
    // jsMinify: 'terser',
    // minify: 'terser',
    // sourcemap: false,
    rollupOptions: {
      //代码分割
      // output: {
      //   chunkFileNames: "assets/js/[name]-[hash].js",
      //   manualChunks: {
      //     vue: ["vue"],
      //     "vue-router": ["vue-router"],
      //     pinia: ["pinia"],
      //     axios: ["axios"],
      //     "vue-i18n": ["vue-i18n"],
      //     "element-plus": ["element-plus"],
      //     "@element-plus/icons-vue": ["@element-plus/icons-vue"],
      //   },
      // },
    },
  },
  preview: {
    //预览选项
    port: 8080,
    open: false,
    strictPort: false,
    cors: true,
    proxy: {
      "/api": {
        target: "http://localhost:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  optimizeDeps: {
    //依赖项预构建选项
    include: [
      // "vue",
      // "vue-router",
      // "pinia",
      // "axios",
      // "vue-i18n",
      // "element-plus",
      // "@element-plus/icons-vue",
      // "@vueuse/core",
      // "@vueuse/integrations",
      // "@vue/shared",
      // "@vue/compiler-sfc",
    ],
  },
  environments: {
    NODE_ENV: "development2",
  },
  worker: {
    format: "es",
    plugins: [],
  },
  ssr: {
    target: "node",
    noExternal: [],
  },
});
